<?php

/*
	[BuyPg] (C) 2010-2011 Buypg
	$Id: ZhengceAction.class.php 2011-7-8 11:43:42 wufujun $
 */
if (!defined('THINK_PATH')) {
	exit('Access Denied');
}

class ZhengceAction extends BpAction{
	/**
	 * +----------------------------------------------------------
	 * 默认操作
	 * +----------------------------------------------------------
	 */
	public function index(){
		global $_SGLOBAL;
		//继承初始网站系统相关信息
		$pgsys = $this->PublicPgsys;
		//网站系统相关设置在当前控制器私有设置
		$pgsys['sys_set']['set_footer_tools'] = 1; //网站页脚 ”常用工具“ 显示
		$_GET['classid'] = 3;
		if(isset($_GET['classid']))
		{
			$strWhere = "class = ".$_GET['classid'];
			$DbClass = M("NewsClass");
			$arrClass = $DbClass->where("class_id = ".$_GET['classid'])->find();
			if(!$arrClass)
			{
				$this->error("您访问的页面不存在！");
			}
			else
			{
				$strClassName = $arrClass['class_name'];
			}
		}
		else
		{
			$strClassName = "全部分类";
		}

		// is the search page
		if(isset($_GET["key"]))
		{
			$strKeyword = trim($_GET["key"]);
			$strClassName = "搜索新闻";
			$strWhere = " (news_title like '%".$strKeyword."%' or news_content like '%".$strKeyword."%' )  ";
		}
		$DbNews = M('News');
		import("@.ORG.Page"); //导入分页类
		import("@.ORG.Input");//导入Input类
		$count = $DbNews->where($strWhere)->count();    //计算总数
		$p = new Page ( $count, 20 );
		$NewsList = $DbNews->where($strWhere)->limit($p->firstRow.','.$p->listRows)->order("news_id desc")->select();
		foreach ($NewsList as $key=>$value)
		{
			$NewsList[$key]['news_content'] = Input::deleteHtmlTags(Input::safeHtml($value['news_content']));
			$NewsList[$key]['news_content'] = msubstr($NewsList[$key]['news_content'], 0, 300, 'utf-8', FALSE);
		}
		$p->setConfig('header','篇记录');
		$p->setConfig('prev','<');
		$p->setConfig('next','>');
		$p->setConfig('first','<<');
		$p->setConfig('last','>>');
		$p->setConfig('theme', ' <span>%nowPage%/%totalPage% 页 </span> %first% %upPage% %linkPage% %downPage% %end%');
		$page = $p->show(1);
		//定义左侧分类
		$LeftCate = getLeftCategory_news();
		//定义右侧专题列表
		$RightZT = getRightZT();
		//模板输出
		$this->assign('sys_set' , $pgsys['sys_set']); //网站系统相关设置当前私有设置模板输出
		$this->assign('leftcate_news' , $LeftCate);
		$this->assign('rightzt' , $RightZT);
		$this->assign('newslist' , $NewsList);
		$this->assign("ClassName", $strClassName);
		$this->assign('page' , $page);
		//模板输出
		$this->display('./Tpl/default/News/index.html');
	}
}
?>
